<?php

namespace App\Repository\Orders;

use App\Models\Orders\OrdersRemarkModel as model;
use App\Repository\BaseRepository;

class OrdersRemarkRepository extends BaseRepository
{
    public $model;
    public $log;

    public function __construct()
    {
        $this->model = new model();
        parent::__construct();
    }

    public function remarkLogs($orderId, $page = 1, $limit = 10)
    {
        $total = 0;
        $where = ['orders_id' => $orderId];
        if ($page <= 1) {
            $total = $this->model->where($where)->count('id');
        }
        $rows = $this->model->with(["user" => function ($query) {
            $query->select(['id', 'nick_name']);
        }])->where($where)->select(['users_id', 'created_at', 'remark'])
            ->page($page, $limit)
            ->orderByDesc('id')->get();
        return $this->returnMsg(200, '操作成功', $rows, $total);
    }
}
